<?php

namespace app\api\controller;

use app\admin\model\hot\Searchs;
use think\Db;
use think\Request;
use app\common\controller\Api;
use think\Validate;

class Hotsearch extends Api
{
    protected static $model = null;
    protected $noNeedLogin = ['create', 'index'];
    protected $noNeedRight = '*';

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        self::$model = new Searchs();
    }

    /**
     * 热搜列表
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $pageSize = input('page_size', 15);
        $list = self::$model
            ->order('num desc')
            ->paginate($pageSize)->each(function ($item) {
                $item['createtime'] = date('Y-m-d H:i:s', $item['createtime']);
            });

        $this->success('热搜列表', $list);
    }
}